<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    var data = [{
        "a":"sky",
        "b":"moon"
    },{
        "a":"sky2",
        "b":"moon2"
    },{
        "a":"sky3",
        "b":"moon3"
    }];
    //    for(var i = 0;i < arr.length;i++){
    //        console.log(i);
    //        if(i=2){
    ////            console.log(i + 1);
    //        }
    //    }
    var a = 2;
    function test(data, a) {
        var s = "";
        for (var i = 0; i < data.length; i++) {
            console.log(i);
            if(data[i].a == a){
//               alert(1);
               console.log(i);
           }
        }
    };
    test(data,"sky3");
</script>
</body>
</html>